using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;


namespace GraphicProcessor {
	/// <summary>
	/// Summary description for TilesPalette.
	/// </summary>
	public class BitmapInspector : System.Windows.Forms.Form {
		private System.Windows.Forms.PictureBox tileZone;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public BitmapInspector(Bitmap[] bmpPalette, Size tileSize ) {
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			Size size=new Size();


			size.Width=tileZone.Width / tileSize.Width;
			size.Height=tileZone.Height / tileSize.Height;

			DrawPalette( bmpPalette, size, 0);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if(components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
			this.tileZone = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// tileZone
			// 
			this.tileZone.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tileZone.Name = "tileZone";
			this.tileZone.Size = new System.Drawing.Size(552, 318);
			this.tileZone.TabIndex = 0;
			this.tileZone.TabStop = false;
			// 
			// BitmapInspector
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(552, 318);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.tileZone});
			this.Name = "BitmapInspector";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "TilesPalette";
			this.TopMost = true;
			this.Load += new System.EventHandler(this.BitmapInspector_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void DrawPalette( Bitmap[] bmpPalette, Size tileSize, int start) {

			int screenLenght=tileSize.Width * tileSize.Height;

			int y=0, x=0;
			tileZone.Image=new Bitmap(tileZone.Width, tileZone.Height);
			Graphics g=Graphics.FromImage( tileZone.Image );
			for (int t=start; t<bmpPalette.Length && t < screenLenght; t++) {
				Image img=(Image) bmpPalette[t];
				g.DrawImage( (Image) img, x, y);
				x+= img.Width;
				if (x > tileZone.Width) {
					y+=img.Height;
					x=0;
				}
				
			} //fin del for

		}

		private void BitmapInspector_Load(object sender, System.EventArgs e) {
		
		}

	}
}